<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
  <head>
    <th:block th:include="include :: header('修改学习视频')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
  </head>
  <body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
      <form
        class="form-horizontal m"
        id="form-video-edit"
        th:object="${djStudyVideo}"
      >
        <input name="id" th:field="*{id}" type="hidden" />
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label is-required">视频标题：</label>
            <div class="col-sm-8">
              <input
                name="title"
                th:field="*{title}"
                class="form-control"
                type="text"
                required
              />
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">分类：</label>
            <div class="col-sm-8">
              <select name="category" class="form-control" id="category">
                <option value="LLXX">理论学习</option>
                <option value="DSJY">党史教育</option>
                <option value="ZCJD">政策解读</option>
                <option value="XJSJ">先进事迹</option>
              </select>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">封面图片：</label>
            <div class="col-sm-8">
              <input type="hidden" name="coverUrl" th:field="*{coverUrl}" />
              <div class="file-loading">
                <input
                  class="form-control file-upload"
                  id="coverUrl"
                  name="file"
                  type="file"
                />
              </div>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label is-required">视频资源：</label>
            <div class="col-sm-8">
              <input type="hidden" name="videoUrl" th:field="*{videoUrl}" />
              <div class="file-loading">
                <input
                  class="form-control file-upload"
                  id="videoUrl"
                  name="file"
                  type="file"
                />
              </div>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">视频时长(秒)：</label>
            <div class="col-sm-8">
              <input
                name="duration"
                th:field="*{duration}"
                class="form-control"
                type="text"
              />
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">视频描述：</label>
            <div class="col-sm-8">
              <textarea name="description" class="form-control">
[[*{description}]]</textarea
              >
            </div>
          </div>
        </div>
      </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
      var prefix = ctx + "learn/video";
      $("#form-video-edit").validate({
        focusCleanup: true,
      });

      function submitHandler() {
        if ($.validate.form()) {
          $.operate.save(prefix + "/edit", $("#form-video-edit").serialize());
        }
      }

      $(".file-upload").each(function (i) {
        var val = $("input[name='" + this.id + "']").val();
        $(this)
          .fileinput({
            uploadUrl: ctx + "common/upload",
            initialPreviewAsData: true,
            initialPreview: [val],
            maxFileCount: 1,
            autoReplace: true,
          })
          .on("fileuploaded", function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(
              data.response.fileName
            );
          })
          .on("fileremoved", function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val("");
          });
        $(this).fileinput("_initFileActions");
      });
    </script>
  </body>
</html>
